package com.sunplus.common.core.ossstorage.aliyunstorage;

/**
 * @author shaoqi
 * @ClassName AliyunOssUtil
 * @Description TODO
 * @date 2021/2/9 0009
 */
public class AliyunOssUtil {



    static final String FILE_SPLIT= "/";

    static final String FILE_SPLIT_START= "~/";

    /**
     * 修复文件路径变成标准化数据
     * @param path 需要修复的路径值
     * @return 修复之后的路径值
     */
    public static String fixFilePath(String path)
    {
        path = path.replace("\\", "/").replace("//", "/");
        if (path.equals(FILE_SPLIT))
        {
            path = "";
        }
        else
        {
            if (path.startsWith(FILE_SPLIT))
            {
                path = path.substring(1, path.length()-1);
            }
            else if (path.startsWith(FILE_SPLIT_START))
            {
                path = path.substring(2, path.length()-1);
            }
        }

        return path;
    }


    public static class Util
    {

        //通过路径来获取文件或者文件夹的名字
        public static String getEntityName(String path)
        {
            //文件分割符号


            if(path.endsWith(FILE_SPLIT))
            {
                path=path.substring(0,path.length()-2);
            }

            int start = path.lastIndexOf(FILE_SPLIT);
            if (start >= 0)
            {
                return path.substring(start + 1, path.length() - 1);
            }
            return path;
        }
    }
}
